/*
 * 文件名：OwnerAddressServiceImpl.java
 * 版权：Copyright by hlst
 * 描述：
 * 修改人：liuziyu
 * 修改时间：2016年7月12日
 * 跟踪单号：
 * 修改单号：
 * 修改内容：
 */

package com.zcsy.manage.service.mall.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.zcsy.manage.model.mall.OwnerAddress;
import com.zcsy.manage.persistence.mall.OwnerAddressDao;
import com.zcsy.manage.service.mall.IOwnerAddressService;

/**
 * @Title: OwnerAddressServiceImpl.java
 * @Package： com.zcsy.manage.service.mall.impl 
 * @Description: 送货地址实现类
 * @author liuziyu liuziyuwri@foxmail.com
 * @Copyright: 2016 武汉恒数利通软件有限公司 All rights reserved.
 * @date 2016年7月12日
 * @version 1.0
 * @see JDK1.7.0_75
 * @since
 */
@Service
public class OwnerAddressServiceImpl implements IOwnerAddressService{

	@Autowired
	private OwnerAddressDao ownerAddressDao;
	
	@Override
	public List<OwnerAddress> getOwnerAddressByOwnerId(String OwnerId) {
		return ownerAddressDao.getOwnerAddressByOwnerId(OwnerId);
	}
	
	@Override
	public int insertAddress(OwnerAddress newAddress){
		return ownerAddressDao.insertAddress(newAddress);
	}
	
	@Override
	public int updateAddress(OwnerAddress newAddress){
		OwnerAddress oldAddress = ownerAddressDao.selectByPrimaryKey(newAddress.getId());
		
		oldAddress.setRecepientName(newAddress.getRecepientName());
		oldAddress.setRegionId(newAddress.getRegionId());
		oldAddress.setUnitId(newAddress.getUnitId());
		oldAddress.setBuildingId(newAddress.getBuildingId());
		oldAddress.setHouseId(newAddress.getHouseId());
		oldAddress.setRecepientPhone(newAddress.getRecepientPhone());
		oldAddress.setOwnerId(newAddress.getOwnerId());
		oldAddress.setProvinceId(newAddress.getProvinceId());
		oldAddress.setCityId(newAddress.getCityId());
		oldAddress.setAreaId(newAddress.getAreaId());
		oldAddress.setCellId(newAddress.getCellId());
		oldAddress.setDetailAddress(newAddress.getDetailAddress());
		oldAddress.setDefaultFlag(newAddress.getDefaultFlag());
		
		return ownerAddressDao.updateAddress(oldAddress);
	}
	
	@Override
	public int updateDefaultFlagToZero(String id){
		return ownerAddressDao.updateDefaultFlagToZero(id);
	}

	@Override
	public OwnerAddress selectDefaultByOwnerId(String ownerId) {
		return ownerAddressDao.selectDefaultByOwnerId(ownerId);
	}

	@Override
	public int updateDefaultFlag(String ownerId, String cellId) {
		return ownerAddressDao.updateDefaultFlag(ownerId, cellId);
	}

	@Override
	public List<OwnerAddress> selectAddressByOwnerIdAndCellId(
			OwnerAddress ownerAddress) {
		return ownerAddressDao.selectAddressByOwnerIdAndCellId(ownerAddress);
	}

	@Override
	public Integer selectCountByOwnerIdAndCellId(String ownerId, String cellId) {
		return ownerAddressDao.selectCountByOwnerIdAndCellId(ownerId, cellId);
	}

	@Override
	public Integer deleteByPrimaryKey(String id) {
		return ownerAddressDao.deleteByPrimaryKey(id);
	}

	@Override
	public OwnerAddress selectByPrimaryKey(String addressId) {
		return ownerAddressDao.selectByPrimaryKey(addressId);
	}

	@Override
	public Integer selectDefaultFlagCount(String ownerId, String cellId) {
		return ownerAddressDao.selectDefaultFlagCount(ownerId, cellId);
	}

	@Override
	public Integer updateToDefaultAddress(String id) {
		return ownerAddressDao.updateToDefaultAddress(id);
	}

}
